package com.yimi.policyservice.repository;

import com.yimi.policyservice.entity.base.policy.PolicyAccfundItem;
import com.yimi.policyservice.entity.base.policy.PolicySocialItem;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface PolicyAccfundItemRepository extends JpaRepository<PolicyAccfundItem,String> {

    @Query(value = "select item_type_code from t_policy_accfund_item where product_id =?1",nativeQuery = true)
    List<String> findItemTypeCodeByProductId(String productId);

    PolicyAccfundItem findFirstByProductIdAndItemTypeCode(String productId, String code);

    List<PolicyAccfundItem> findByProductId(String id);

    @Modifying
    @Transactional
    @Query(value = "delete from t_policy_accfund_item where product_id in ?1",nativeQuery = true)
    void deleteByProductIdIn(List<String> ids);
    @Modifying
    @Transactional
    @Query(value = "delete from t_policy_accfund_item where  product_id =?1 and item_type_code= ?2",nativeQuery = true)
    int deleteAccfunCode(String productId, String code);
}
